import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM7YObVLUgE9b3JAha6EcreYVzbupWzF\n' +
  'ekFA/h5saPvTsI0RuEryYxM2FIvZ4qm6/JpEQazaCgIXrXdOXcMwqUECAwEAAQ=='

const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAztg5tUtSAT1vckCF\n' +
  'roRyt5hXNu6lbMV6QUD+Hmxo+9OwjRG4SvJjEzYUi9niqbr8mkRBrNoKAhetd05d\n' +
  'wzCpQQIDAQABAkBHwUzrrpBpK7XQrb9yVjIxrKB8xvcOL8eEgZZmWXdl/F7dHwqF\n' +
  'iti7ztBWM5PzDjo7Xk7zUg/Ty+FamKK3sK0BAiEA9fU3xJgTKmZBj+6uaWh7rX7T\n' +
  'P0iSdxIU9zxALzoTezECIQDXSjDoMg0ryV6h2z+D2tWENvdrHZDJM7ABElmZT+hr\n' +
  'EQIhAMJ5iQXmJMlSnyZaWAe6eIgfDpMsI7sIThGKz0lIR10RAiAKELXopS5odamu\n' +
  '94koqPqCi+9VWrSCM6Bu7GSz/kBngQIgYBsLK2bntnhXY1W6xaYJUkcYQXg4XGzk\n' +
  'Hbk8qTxmO10='

// 加密
export function encrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}
